package com.xunyin.modules.device.rest;

import com.xunyin.modules.aop.ForbidSubmit;
import com.xunyin.modules.device.domain.TDevicePowerSet;
import com.xunyin.modules.device.service.TDevicePowerSetService;
import com.xunyin.modules.device.service.dto.TDeviceQueryCriteria;
import com.xunyin.modules.log.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author xunyinyunshang
 * 硬件设备通断电设置
 * Created by xunyinyunshang <3594419785@qq.com>
 * CopyRight 讯音云商 https://www.tonetn.com
 * @date 2023-10-21
 */
@Slf4j
@AllArgsConstructor
@Api(tags = "共享空间:硬件设备通断电设置")
@RestController
@RequestMapping("api")
public class TDevicePowerSetController {

    private final TDevicePowerSetService tDevicePowerSetService;

    @Log("查询硬件设备通断电设置")
    @ApiOperation("查询硬件设备通断电设置")
    @GetMapping(value = "/tDevicePowerSet")
    public ResponseEntity getTDevicePowerSet(TDeviceQueryCriteria criteria, Pageable pageable) {

/*        List<TDevicePowerSet> devicePowerSetList = tDevicePowerSetService.list();
        TDevicePowerSet tDevicePowerSet =devicePowerSetList.get(0);
        log.info("tDevicePowerSet.getDeviceOpt():"+tDevicePowerSet.getDeviceOpt());*/
        Map<String, Object> queryAll = tDevicePowerSetService.queryAll(criteria, pageable);
        return new ResponseEntity<>(queryAll, HttpStatus.OK);
    }

    @ForbidSubmit
    @Log("新增硬件设备通断电设置")
    @ApiOperation("新增硬件设备通断电设置")
    @PostMapping(value = "/tDevicePowerSet")
    public ResponseEntity<Object> create(@Validated @RequestBody TDevicePowerSet resources) {

        return new ResponseEntity<>(tDevicePowerSetService.save(resources), HttpStatus.CREATED);
    }

    @ForbidSubmit
    @Log("修改硬件设备通断电设置")
    @ApiOperation("修改硬件设备通断电设置")
    @PutMapping(value = "/tDevicePowerSet")
    public ResponseEntity<Object> update(@Validated @RequestBody TDevicePowerSet resources) {
        tDevicePowerSetService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
}
